<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" xmlns:xu="http://www.xmldb.org/xupdate">

	<p:processor name="oxf:pipeline">
		<p:input name="config" href="../session.xpl"/>
		<p:output name="data" id="session"/>
	</p:processor>

	<!--Transforme js query into XML-->
	<p:processor name="oxf:pipeline">
		<p:input name="config" href="utils/jsArrayToXML.xpl"/>
		<p:output name="data" id="query"/>
	</p:processor>

	<!--LANG selector-->
	<p:choose href="#session">
		<p:when test="/session/lang != 'en'">

			<!--load translation-->
			<p:processor name="oxf:pipeline">
				<p:input name="data" href="#session#xpointer(/session/lang)"/>
				<p:input name="config" href="/apps/engine/utils/XMLtranslation.xpl"/>
				<p:output name="data" id="translation"/>
			</p:processor>

			<p:processor name="oxf:unsafe-xslt">
				<p:input name="data" href="#query"/>
				<p:input name="translation" href="#translation"/>
				<p:input name="config">
					<xsl:stylesheet version="2.0" xmlns:foo="http://something"  exclude-result-prefixes="foo">
						<xsl:import href="/apps/engine/utils/translate_fct.xsl"/>
						<xsl:template match="/">
							<json>
								<xsl:for-each select="/array/e">
									<object>
										<xsl:variable name="cur_val" select="."/>
										<original>
											<xsl:value-of select="."/>
										</original>
										<translated>
											<xsl:value-of select="foo:translate(., doc('input:translation')/translation)"/>
										</translated>
									</object>
								</xsl:for-each>
							</json>
						</xsl:template>
					</xsl:stylesheet>
				</p:input>
				<p:output name="data" id="document"/>
			</p:processor>
		</p:when>
		<p:otherwise>
			<!--EN reproduce the query-->
			<p:processor name="oxf:unsafe-xslt">
				<p:input name="data" href="#query"/>
				<p:input name="config">
					<json xsl:version="2.0">
						<xsl:for-each select="/array/e">
							<object>
								<original>
									<xsl:value-of select="."/>
								</original>
								<translated>
									<xsl:value-of select="."/>
								</translated>
							</object>
						</xsl:for-each>
					</json>
				</p:input>
				<p:output name="data" id="document"/>
			</p:processor>
		</p:otherwise>
	</p:choose>

	<!--<p:processor name="oxf:xml-converter">
		<p:input name="config">
			<config>
				<content-type>text/xml</content-type>
				<encoding>utf-8</encoding>
				<version>1.0</version>
				<omit-xml-declaration>true</omit-xml-declaration>
			</config>
		</p:input>
		<p:input name="data" href="#session"/>
		<p:output name="data" id="xml-doc"/>
	</p:processor>

	<p:processor name="oxf:http-serializer">
		<p:input name="config">
			<config>
				<content-type>text/xml</content-type>
				<force-content-type>true</force-content-type>
			</config>
		</p:input>
		<p:input name="data" href="#xml-doc"/>
	</p:processor>-->

	<!--XML to JSON-->
	<p:processor name="oxf:pipeline">
		<p:input name="config" href="utils/json.xpl"/>
		<p:input name="data" href="#document"/>
	</p:processor>

</p:config>